<template>
  <organ-save-edit-auto @onSubmit="onSubmit" :form-data="formData"></organ-save-edit-auto>
</template>

<script>

import OrganSaveEditAuto from './OrganSaveEditAuto'
import {editOrg, orgPublic, queryOrgByOid} from "@/api/operations-center/org";

export default {
  name: "OrganEdit",
  mixins: [orgPublic],
  components: {
    OrganSaveEditAuto
  },
  data() {
    return {
      formData: {
        id: ''
      }
    }
  },
  methods: {
    /**
     * {查询获取指定组织}
     *
     * @author: 宋康
     * @date: 2022/8/17 14:45
     */
    queryOrg() {
      queryOrgByOid(this.$route.query.id || '0').then(res => {
        if (res.status && res.data) {
          this.formData = {
            ...res.data
          }
        }
      })
    },
    /**
     * {修改}
     *
     * @author: 宋康
     * @date: 2022/8/17 10:16
     */
    onSubmit(fromData) {
      editOrg(fromData).then(res => {
        if (res.status) {
          this.$XModal.alert({
            content: '编辑成功',
            status: 'success',
          }).then(() => {
            this.cancel();
          })
        } else {
          this.$XModal.alert({
            content: res['msg'],
            status: 'error',
          })
        }
      })
    },
  },
  mounted() {
    this.queryOrg();
  }
}
</script>

<style lang="scss" scoped>

</style>
